package weaver.interfaces.jjy.duss.action;

import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

/*
 *@Description: 当人事范围编码不为“8004” 或“8007” 或“ZB01”时；根据主表中的“人事范围编码”、“年份”、“节日类型”
 * 将uf_jbfxfhz中的“zt”字段改为1；并将流程主表中的BMSBJRJBF更新到uf_jbfxfhz中的BMSBJRJBF；
 * 将流程主表中的BMSBXJJBF更新到uf_jbfxfhz中的BMSBXJJBF；
 * 将流程明细表中的GRSBJRJBF、GRSBXJJBF更新到uf_jbfxfmx中的GRSBJRJBF、GRSBXJJBF中；
 *@Author: Dusongsong
 *@Date: 2019/12/24
 */
public class WeaHRjbfjxAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet rs = new RecordSet();
        RecordSet rs2 = new RecordSet();
        BaseBean baseBean = new BaseBean();
        String requestid = requestInfo.getRequestid();
        baseBean.writeLog("请求ID" + requestid);
        baseBean.writeLog("调用: WeaHRjbfjxAction");
        String tablename = requestInfo.getRequestManager().getBillTableName();//主表
        rs.executeQuery("select * from " + tablename + " where requestid=?", requestid);
        baseBean.writeLog("select * from " + tablename + " where requestid=" + requestid);
        rs.next();
        String mainid = Util.null2String(rs.getString("id"));//外键
        String werks = Util.null2String(rs.getString("werks"));//人事范围编码
        String bmbm = Util.null2String(rs.getString("bmbm"));//部门编码
        String gjahr = Util.null2String(rs.getString("gjahr"));//年份
        String jrlx = Util.null2String(rs.getString("jrlx"));//假期类型

        String STATE = "1";
        String message = "";
        if ("8004".equals(werks) || "8007".equals(werks) || "ZB01".equals(werks)) {
            //更新汇总表
            String bmsbjrjbf = Util.null2String(rs.getString("bmsbjrjbf"));//部门上报节日加班费
            String bmsbxjjbf = Util.null2String(rs.getString("bmsbxjjbf"));//部门上报现金加班费
            String updateSQL = "update uf_jbfhzb set bmsbjrjbf='" + bmsbjrjbf + "',bmsbxjjbf='" + bmsbxjjbf + "',zt='" + STATE + "' where werks='" + werks + "' and bmbm='" + bmbm + "' and gjahr='" + gjahr + "' and jrlx='" + jrlx + "' ";
            rs.executeUpdate(updateSQL);
            baseBean.writeLog("调用SQL" + updateSQL);
            //更新明细表
            String SQL1 = "select grsbjrjbf,grsbxjjbf,numid  from " + tablename + "_dt1 where mainid='" + mainid + "' and werks='" + werks + "' and gjahr='" + gjahr + "' and jrlx='" + jrlx + "' and bmbm='" + bmbm + "'";
            baseBean.writeLog(SQL1);
            rs2.execute(SQL1);
            while (rs2.next()) {
                String numid = Util.null2String(rs2.getString("NUMID"));//唯一标识
                String grsbjrjbf = Util.null2String(rs2.getString("GRSBJRJBF"));//个人上报节日加班费
                String grsbxjjbf = Util.null2String(rs2.getString("GRSBXJJBF"));//个人上报现金加班费
                String updateSQL1 = "update uf_jbfmxb set grsbjrjbf='" + grsbjrjbf + "' ,grsbxjjbf= '" + grsbxjjbf + "' where werks='" + werks + "' and gjahr='" + gjahr + "' and bmbm='" + bmbm + "' and jrlx='" + jrlx + "' and numid='"+numid+"'";
                rs.executeUpdate(updateSQL1);
                baseBean.writeLog("执行语句：" + updateSQL1);
                requestInfo.getRequestManager().setMessageid("111111");
                requestInfo.getRequestManager().setMessagecontent(message);
            }
            return Action.SUCCESS;
        } else {
            //更新汇总表
            String bmsbjrjbf = Util.null2String(rs.getString("bmsbjrjbf"));//部门上报节日加班费
            String bmsbxjjbf = Util.null2String(rs.getString("bmsbxjjbf"));//部门上报现金加班费
            String updateSQL = "update uf_jbfhzb set bmsbjrjbf='" + bmsbjrjbf + "',bmsbxjjbf='" + bmsbxjjbf + "',zt='" + STATE + "' where werks='" + werks + "' and gjahr='" + gjahr + "' and jrlx='" + jrlx + "' ";
            rs.executeUpdate(updateSQL);
            baseBean.writeLog("调用SQL" + updateSQL);
            //更新明细表
            String SQL1 = "select grsbjrjbf,grsbxjjbf,numid  from " + tablename + "_dt1 where mainid='" + mainid + "' and werks='" + werks + "' and gjahr='" + gjahr + "' and jrlx='" + jrlx + "'";
            baseBean.writeLog(SQL1);
            rs2.execute(SQL1);
            while (rs2.next()) {
                String numid = Util.null2String(rs2.getString("NUMID"));//唯一标识
                String grsbjrjbf = Util.null2String(rs2.getString("GRSBJRJBF"));//个人上报节日加班费
                String grsbxjjbf = Util.null2String(rs2.getString("GRSBXJJBF"));//个人上报现金加班费
                String updateSQL1 = "update uf_jbfmxb set grsbjrjbf='" + grsbjrjbf + "' ,grsbxjjbf= '" + grsbxjjbf + "' where werks='" + werks + "' and gjahr='" + gjahr + "' and jrlx='" + jrlx + "' and numid='"+numid+"'";
                rs.executeUpdate(updateSQL1);
                baseBean.writeLog("执行语句：" + updateSQL1);
                requestInfo.getRequestManager().setMessageid("111111");
                requestInfo.getRequestManager().setMessagecontent(message);
            }
            return Action.SUCCESS;
        }
    }
}

